package com.pai4j.user.controller;

import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.domain.vo.response.PendingApprovalResponseVO;
import com.pai4j.remote.user.PendingApprovalClient;
import com.pai4j.user.service.approval.PendingApprovalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 统一待审核Controller
 * 提供统一的待审核查询、标记已读、未读统计接口
 */
@Slf4j
@RestController
public class PendingApprovalController implements PendingApprovalClient {

    @Autowired
    private PendingApprovalService pendingApprovalService;

    @Override
    public PAIResponseBean<List<PendingApprovalResponseVO>> listPendingApprovals(
            String approverAccount, Integer approvalType, Integer approvalStatus) {
        
        List<PendingApprovalResponseVO> result = pendingApprovalService.listPendingApprovals(
                approverAccount, approvalType, approvalStatus);
        
        return PAIResponseBeanUtil.success(result);
    }

    @Override
    public PAIResponseBean<List<PendingApprovalResponseVO>> listUnreadPendingApprovals(
            String approverAccount, Integer approvalType, Integer approvalStatus) {
        
        List<PendingApprovalResponseVO> result = pendingApprovalService.listUnreadPendingApprovals(
                approverAccount, approvalType, approvalStatus);
        
        return PAIResponseBeanUtil.success(result);
    }

    @Override
    public PAIResponseBean<Long> countUnreadPendingApprovals(
            String approverAccount, Integer approvalType, Integer approvalStatus) {
        
        Long count = pendingApprovalService.countUnreadPendingApprovals(
                approverAccount, approvalType, approvalStatus);
        
        return PAIResponseBeanUtil.success(count);
    }

    @Override
    public PAIResponseBean<Integer> markApprovalsAsRead(
            String approverAccount, Integer approvalType, Integer approvalStatus) {
        
        int count = pendingApprovalService.markApprovalsAsRead(
                approverAccount, approvalType, approvalStatus);
        
        return PAIResponseBeanUtil.success(count);
    }
}
